<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button>跳转</button>
  <h2></h2>
  <script>
    var btn = document.querySelector('button')
    var h2 = document.querySelector('h2')

    btn.onclick = function() {
      location.href = 'http://www.jd.com'
    }

    var fn = function() {
      if(time === 0) {
        location.href = 'http://www.jd.com'
        return 
      }
      h2.innerText = '你将在' + time +'秒跳转'
      time -= 1
    }
    
    var time = 5

    fn()
    setInterval(fn, 1000)


  </script>
</body>
</html>